

//
//  CartCell.m
//  ZQLearn
//
//  Created by macfeel on 2019/5/15.
//  Copyright © 2019 macfeel. All rights reserved.
//

#import "CartCell.h"

@implementation CartCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = 0;
    self.numberLab.layer.borderColor = [kLightGrayColor CGColor];
    self.numberLab.layer.borderWidth =0.5f;
}


- (void)setModel:(CartModel *)model{
    
    _model = model;
    ///对全选和全反选起作用
    self.tickBtn.selected = model.isSelected;
}



- (void)setIsEdit:(BOOL)isEdit{
    _isEdit = isEdit;
    // 点击了编辑/完成按钮，显示不同的页面
    if (isEdit==NO) {

        self.numberLab.hidden = NO;
        self.minusBtn.hidden = NO;
        self.plusBtn.hidden = NO;

        
    } else {
        
        self.numberLab.hidden = YES;
        self.minusBtn.hidden = YES;
        self.plusBtn.hidden = YES;

    }
}


//勾选按钮
- (IBAction)tickBtnAction:(UIButton *)sender {
    
    self.tickBtn.selected = !self.tickBtn.selected;
    //标记为已选中状态
    self.model.isSelected = self.tickBtn.selected;
    if ([_delegate respondsToSelector:@selector(cartCell:didCilckedTickButton:atIndexPath:)]) {
        [_delegate cartCell:self didCilckedTickButton:self.tickBtn.selected atIndexPath:self.indexPath];
    }
}


///减少
- (IBAction)minusBtnAction:(UIButton *)sender {
    YYLog(@"jian");
    if ([self.numberLab.text isEqualToString:@"1"]) {
        return;
    }
    self.numberLab.text = [NSString stringWithFormat:@"%ld",[self.numberLab.text integerValue]-1];
    if ([_delegate respondsToSelector:@selector(cartCell:didChangeGoodsNumber:andProductId:atIndexPath:)]) {
        [_delegate cartCell:self didChangeGoodsNumber:[self.numberLab.text integerValue] andProductId:[self.productId integerValue] atIndexPath:self.indexPath];
    }
}

//增多

- (IBAction)plusBtnAction:(UIButton *)sender {

   YYLog(@"jia");
    self.numberLab.text = [NSString stringWithFormat:@"%ld",[self.numberLab.text integerValue]+1];
    if ([_delegate respondsToSelector:@selector(cartCell:didChangeGoodsNumber:andProductId:atIndexPath:)]) {
        [_delegate cartCell:self didChangeGoodsNumber:[self.numberLab.text integerValue] andProductId:[self.productId integerValue] atIndexPath:self.indexPath];
    }
    
}






- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
    // Configure the view for the selected state
}

@end
